Reference
R. Eberhart and J. Kennedy. (1995).
“A new optimizer using particle swarm theory”.
Proceedings of the Sixth International Symposium on Micro Machine and Human Science.
Pseudocode
- Set algorithm parameters C$_1$, C$_2$, and W
- Initialize swarm $\mathbb{S}=\{\mathbf{p}_1,\ldots,\mathbf{p}_N\}$.
- For each $\mathbf{p}_i \in \mathbb{S}$:
- Initialize $\mathbf{p}_i=\{$x, v, x$_{pbest}$, f(x), f(x$_{pbest}$)$\}$
- Evaluate f(x)
- $\{$x$_{pbest}$, f(x$_{pbest}$)$\}\gets\{$ x, f(x)$\}$
- update_best()
- While termination criterion is not fulfilled:
- For each $\mathbf{p}_i\in \mathbb{P}$ (with random sequence):
- set_neighborhood()
- $\{$x$_{lbest}$, f(x$_{lbest}$)$\}\gets$ get_best_neighbor($i$)
- v $\gets$ next_velocity(x$_{lbest}$, W, C$_1$, C$_2$)
- x $\gets$ move(x, v)
- x $\gets$ clamp_velocity(x)
- Evaluate f(u)
- If better(f(x), f(x$_{pbest}$)):
- $\{$x$_{pbest}$, f(x$_{pbest}$) $\}\gets\{$x, f(x)$\}$
- update_best($\{$x, f(x)$\}$)
- Output results
swarm
Class view
template <typename Particle>
class swarm : public population<Particle>
Links: population
Data member
Name |
Type |
Utility |
m_C1 m_C2 |
real |
The value of accelerators C$_1$ and C$_2$ |
m_weight |
real |
The value of inertia weight W |
m_link |
vector<vector<bool>> |
The connections between particles |
m_flag_best_impr |
bool |
Whether the global best particle improves |
Member function
Name |
Utility |
evolve() ⊕ |
|
set_neighborhood() |
The adaptive random topology by default |
get_best_neighbor(idx) |
Return the best neighbor of the idx -th particle |
particle
Class view
class particle : public individual<>
Links: individual
Data member
Name |
Type |
Utility |
m_pbest |
solution<> |
The personal best position |
m_vel |
vector<real> |
The velocity vector |
Member function
Name |
Utility |
initialize_velocity() |
|
next_velocity(lbest, w, c1, c2) |
|
move() |
|
clamp_velocity() |
|
SPSO-07
Reference
C. Maurice. (2007). “Standard pso 2007 (spso-07)”.
Command line arguments example
AN=SPSO07 PS=100
Class view
class SPSO07 final : public algorithm
Data member
Name |
Type |
Utility |
m_pop |
swarm<particle07> |
|
Member function
Name |
Utility |
initialize() ⊕ |
|
run_() ⊕ |
|
record() ⊕ |
|
Class view
class particle07 final : public particle
Member function
Name |
Utility |
initialize_velocity() ⊕ |
|
next_velocity(lbest, w, c1, c2) ⊕ |
|
SPSO-11
Reference
C. Maurice. (2011). “Standard PSO 2011 (SPSO-2011)”.
Command line arguments example
AN=SPSO11 PS=100
Class view
class SPSO11 final : public algorithm {
Data member
Name |
Type |
Utility |
m_pop |
swarm<particle11> |
|
Member function
Name |
Utility |
initialize() ⊕ |
|
run_() ⊕ |
|
record() ⊕ |
|
Class view
class particle11 final : public particle
Member function
Name |
Utility |
initialize_velocity() ⊕ |
|
next_velocity(lbest, w, c1, c2) ⊕ |
|
clamp_velocity() ⊕ |
|